This notebook contains plots for the Apple Watch Movelet project comparing the effect of setting different run-time parameter combinations (i.e. number of PCs, including both hands, dominant hand only, or nondominant hand only, number of med-taking sessions to include in the training set) on various prediction metrics.
library(dplyr)
library(tidyr)
library(ggplot2)
library(ggpubr)
library(ggsci)
library(flextable)
source("Code/functions.R")
source("Code/summary.R")
metrics_df <- read.csv('metrics_df.csv')
metrics_df_all_n <- read.csv('metrics_df_all_n.csv')
runtime_df <- read.csv('runtime_df.csv') %>%
mutate(n_train = stringr::str_count(ses, ",") + 1, .before='ses')
metrics_df %>%
filter(pca == 'bothhands') %>%
mutate(npc = as.factor(npc)) %>%
group_by(patient, smooth, npc) %>%
select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>%
summarize_all(mean) %>%
ungroup() %>%
pivot_longer(-c(npc, patient, smooth), names_to = "Metric") %>%
ggplot(aes(x=Metric, y=value, color=npc)) +
geom_boxplot() +
facet_wrap(~smooth) +
theme_bw() + theme(plot.title = element_text(hjust = 0.5)) +
scale_color_lancet()
#ggsave('figures/npc_boxplot.png', dpi=300)
runtime_df %>%
filter(n_train == 1) %>%
group_by(npc) %>%
summarize(mean_runtime = mean(elapsed))
runtime_df %>%
filter(n_train == 1) %>%
mutate(npc = as.factor(npc)) %>%
ggplot(aes(x=npc, y=elapsed)) + geom_boxplot() + ylab('Run time in seconds') + xlab('Number of PCs') + ggtitle('Run time per number of PCs')
Run times relative to 3 npc.
# relative to 3 npc
runtime_df %>%
filter(n_train == 1) %>%
group_by(npc) %>%
summarize(mean_runtime = mean(elapsed)) %>%
mutate(mean_runtime = mean_runtime / min(mean_runtime))
metrics_df_for_plot = metrics_df %>%
filter(npc == 3 | npc == 6) %>%
mutate(npc = as.factor(npc), patient=as.factor(patient)) %>%
group_by(patient, smooth, pca) %>%
select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>%
summarize_all(mean) %>%
ungroup()
metrics_df_for_plot %>%
pivot_longer(-c(pca, patient, smooth), names_to = "Metric") %>%
mutate(pca = recode(.$pca, `bothhands` = "Both Hands", `dominanthand` = "Dominant Hand", `nondominanthand` = "Nondominant Hand")) %>%
ggplot(aes(x=Metric, y=value, color=pca)) +
geom_boxplot() +
facet_wrap(~smooth) +
theme_bw() + theme(plot.title = element_text(hjust = 0.5)) +
scale_color_lancet() +
labs(color='PCA')
Testing differences in metrics (paired T-tests)
bothhands = metrics_df_for_plot %>%
filter(smooth=='Post-Smoothing', pca=='bothhands') %>%
select(where(is.numeric))
domhand = metrics_df_for_plot %>%
filter(smooth=='Post-Smoothing', pca=='dominanthand') %>%
select(where(is.numeric))
nondomhand = metrics_df_for_plot %>%
filter(smooth=='Post-Smoothing', pca=='nondominanthand') %>%
select(where(is.numeric))
dom_vs_both = seq_along(bothhands) %>%
purrr::map(function(i) t.test(pull(domhand, i), # get i-th column
pull(bothhands, i),
paired = TRUE)) %>%
purrr::map(broom::tidy) %>%
setNames(colnames(bothhands)) %>%
dplyr::bind_rows(.id = 'metric') %>%
tibble::add_column(comparison = "Dominant hand v. Both Hands", .before = 'metric')
nondom_vs_both = seq_along(bothhands) %>%
purrr::map(function(i) t.test(pull(nondomhand, i), # get i-th column
pull(bothhands, i),
paired = TRUE)) %>%
purrr::map(broom::tidy) %>%
setNames(colnames(bothhands)) %>%
dplyr::bind_rows(.id = 'metric') %>%
tibble::add_column(comparison = "Nondominant hand v. Both Hands", .before = 'metric')
nondom_vs_dom = seq_along(bothhands) %>%
purrr::map(function(i) t.test(pull(nondomhand, i), # get i-th column
pull(domhand, i),
paired = TRUE)) %>%
purrr::map(broom::tidy) %>%
setNames(colnames(bothhands)) %>%
dplyr::bind_rows(.id = 'metric') %>%
tibble::add_column(comparison = "Nondominant hand v. Dominant hand", .before = 'metric')
rbind(dom_vs_both, nondom_vs_both, nondom_vs_dom)
metrics_df_long = metrics_df %>% filter(pca == 'bothhands', npc==3) %>% group_by(patient, smooth) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% pivot_longer(-c(patient, smooth), names_to = "Metric")
metrics_df_long %>% ggplot(aes(x=Metric, y = value, color=Metric)) + geom_jitter() + geom_boxplot(alpha=0) + facet_wrap(~smooth) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (1 session training)") + theme(plot.title = element_text(hjust = 0.5)) +
scale_color_d3()
# Prepare table with smoothing
table1 = metrics_df %>% filter(smooth=="Pre-Smoothing", pca == 'bothhands', npc==3) %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean)
# Prepare table without smoothing
table2 = metrics_df %>% filter(smooth=="Post-Smoothing", pca == 'bothhands', npc==3) %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% as.data.frame()
# Join tables
tables = cbind(table1, table2[, -1]) %>% round(2)
colnames(tables)[2:11] = paste0(colnames(tables)[2:11], rep(c(".T", ".F"), each = 5))
headers = data.frame(col_keys = colnames(tables),
from = c("Session", rep(c("Pre-Smoothing", "Post-Smoothing"), each=5)),
names = c("Session", colnames(cbind(table1[-1], table2[, -1])))
)
# Print table as flextable
tables %>% flextable::flextable() %>%
set_header_df(mapping = headers, key = "col_keys") %>%
merge_h(part="header") %>%
merge_v(part="header") %>%
theme_vanilla() %>%
width(width = 27, unit = "in") %>%
align(align="center", part="all") %>%
vline(part="header")
Session | Pre-Smoothing | Post-Smoothing | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
Accuracy | Precision | F1.score | Sensitivity | Specificity | Accuracy | Precision | F1.score | Sensitivity | Specificity | |
5 | 0.83 | 0.93 | 0.88 | 0.84 | 0.80 | 0.88 | 0.94 | 0.92 | 0.90 | 0.82 |
6 | 0.81 | 0.92 | 0.86 | 0.81 | 0.79 | 0.86 | 0.94 | 0.90 | 0.87 | 0.83 |
8 | 0.81 | 0.92 | 0.86 | 0.83 | 0.76 | 0.86 | 0.92 | 0.90 | 0.89 | 0.76 |
9 | 0.78 | 0.91 | 0.84 | 0.79 | 0.77 | 0.83 | 0.93 | 0.87 | 0.84 | 0.81 |
11 | 0.78 | 0.89 | 0.84 | 0.80 | 0.71 | 0.81 | 0.89 | 0.86 | 0.85 | 0.70 |
12 | 0.73 | 0.89 | 0.79 | 0.73 | 0.74 | 0.78 | 0.92 | 0.83 | 0.79 | 0.77 |
metrics_df_all_n %>%
filter(pca == 'bothhands', npc==3) %>%
group_by(patient, n_train, smooth) %>%
select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>%
summarize_all(mean) %>%
pivot_longer(-c(patient, n_train, smooth), names_to = "Metric") %>%
ggplot(aes(x=n_train, y = value, color=as.factor(n_train))) +
geom_jitter() + facet_grid(smooth~Metric) + geom_boxplot(alpha=0) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (n session training)") +
theme(plot.title = element_text(hjust = 0.5)) + guides(color=guide_legend(title="N trained med sessions")) + xlab("Train N") +
scale_color_lancet()
metrics_df_long = metrics_df %>% filter(pca == 'bothhands', npc==4) %>% group_by(patient, smooth) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% pivot_longer(-c(patient, smooth), names_to = "Metric")
metrics_df_long %>% ggplot(aes(x=Metric, y = value, color=Metric)) + geom_jitter() + geom_boxplot(alpha=0) + facet_wrap(~smooth) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (1 session training)") + theme(plot.title = element_text(hjust = 0.5)) +
scale_color_d3()
# Prepare table with smoothing
table1 = metrics_df %>% filter(smooth=="Pre-Smoothing", pca == 'bothhands', npc==4) %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean)
# Prepare table without smoothing
table2 = metrics_df %>% filter(smooth=="Post-Smoothing", pca == 'bothhands', npc==4) %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% as.data.frame()
# Join tables
tables = cbind(table1, table2[, -1]) %>% round(2)
colnames(tables)[2:11] = paste0(colnames(tables)[2:11], rep(c(".T", ".F"), each = 5))
headers = data.frame(col_keys = colnames(tables),
from = c("Session", rep(c("Pre-Smoothing", "Post-Smoothing"), each=5)),
names = c("Session", colnames(cbind(table1[-1], table2[, -1])))
)
# Print table as flextable
tables %>% flextable::flextable() %>%
set_header_df(mapping = headers, key = "col_keys") %>%
merge_h(part="header") %>%
merge_v(part="header") %>%
theme_vanilla() %>%
width(width = 27, unit = "in") %>%
align(align="center", part="all") %>%
vline(part="header")
Session | Pre-Smoothing | Post-Smoothing | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
Accuracy | Precision | F1.score | Sensitivity | Specificity | Accuracy | Precision | F1.score | Sensitivity | Specificity | |
5 | 0.84 | 0.93 | 0.89 | 0.85 | 0.79 | 0.88 | 0.93 | 0.92 | 0.91 | 0.79 |
6 | 0.82 | 0.92 | 0.87 | 0.83 | 0.78 | 0.87 | 0.93 | 0.91 | 0.89 | 0.80 |
8 | 0.81 | 0.92 | 0.87 | 0.83 | 0.76 | 0.85 | 0.93 | 0.90 | 0.88 | 0.78 |
9 | 0.80 | 0.92 | 0.85 | 0.81 | 0.78 | 0.85 | 0.93 | 0.89 | 0.86 | 0.81 |
11 | 0.79 | 0.90 | 0.85 | 0.81 | 0.73 | 0.82 | 0.91 | 0.87 | 0.86 | 0.71 |
12 | 0.74 | 0.90 | 0.79 | 0.73 | 0.75 | 0.77 | 0.91 | 0.81 | 0.78 | 0.74 |
metrics_df_all_n %>%
filter(pca == 'bothhands', npc==4) %>%
group_by(patient, n_train, smooth) %>%
select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>%
summarize_all(mean) %>%
pivot_longer(-c(patient, n_train, smooth), names_to = "Metric") %>%
ggplot(aes(x=n_train, y = value, color=as.factor(n_train))) +
geom_jitter() + facet_grid(smooth~Metric) + geom_boxplot(alpha=0) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (n session training)") +
theme(plot.title = element_text(hjust = 0.5)) + guides(color=guide_legend(title="N trained med sessions")) + xlab("Train N") +
scale_color_lancet()
metrics_df_long = metrics_df %>% filter(pca == 'bothhands', npc==5) %>% group_by(patient, smooth) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% pivot_longer(-c(patient, smooth), names_to = "Metric")
metrics_df_long %>% ggplot(aes(x=Metric, y = value, color=Metric)) + geom_jitter() + geom_boxplot(alpha=0) + facet_wrap(~smooth) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (1 session training)") + theme(plot.title = element_text(hjust = 0.5)) +
scale_color_d3()
# Prepare table with smoothing
table1 = metrics_df %>% filter(smooth=="Pre-Smoothing", pca == 'bothhands', npc==5) %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean)
# Prepare table without smoothing
table2 = metrics_df %>% filter(smooth=="Post-Smoothing", pca == 'bothhands', npc==5) %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% as.data.frame()
# Join tables
tables = cbind(table1, table2[, -1]) %>% round(2)
colnames(tables)[2:11] = paste0(colnames(tables)[2:11], rep(c(".T", ".F"), each = 5))
headers = data.frame(col_keys = colnames(tables),
from = c("Session", rep(c("Pre-Smoothing", "Post-Smoothing"), each=5)),
names = c("Session", colnames(cbind(table1[-1], table2[, -1])))
)
# Print table as flextable
tables %>% flextable::flextable() %>%
set_header_df(mapping = headers, key = "col_keys") %>%
merge_h(part="header") %>%
merge_v(part="header") %>%
theme_vanilla() %>%
width(width = 27, unit = "in") %>%
align(align="center", part="all") %>%
vline(part="header")
Session | Pre-Smoothing | Post-Smoothing | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
Accuracy | Precision | F1.score | Sensitivity | Specificity | Accuracy | Precision | F1.score | Sensitivity | Specificity | |
5 | 0.84 | 0.92 | 0.89 | 0.86 | 0.78 | 0.89 | 0.94 | 0.93 | 0.93 | 0.80 |
6 | 0.81 | 0.92 | 0.86 | 0.83 | 0.78 | 0.86 | 0.93 | 0.89 | 0.87 | 0.82 |
8 | 0.82 | 0.92 | 0.87 | 0.84 | 0.76 | 0.86 | 0.93 | 0.90 | 0.90 | 0.75 |
9 | 0.80 | 0.91 | 0.85 | 0.82 | 0.76 | 0.85 | 0.93 | 0.89 | 0.87 | 0.80 |
11 | 0.79 | 0.90 | 0.84 | 0.81 | 0.71 | 0.84 | 0.93 | 0.88 | 0.87 | 0.76 |
12 | 0.73 | 0.89 | 0.78 | 0.73 | 0.73 | 0.75 | 0.90 | 0.79 | 0.76 | 0.76 |
metrics_df_all_n %>%
filter(pca == 'bothhands', npc==5) %>%
group_by(patient, n_train, smooth) %>%
select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>%
summarize_all(mean) %>%
pivot_longer(-c(patient, n_train, smooth), names_to = "Metric") %>%
ggplot(aes(x=n_train, y = value, color=as.factor(n_train))) +
geom_jitter() + facet_grid(smooth~Metric) + geom_boxplot(alpha=0) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (n session training)") +
theme(plot.title = element_text(hjust = 0.5)) + guides(color=guide_legend(title="N trained med sessions")) + xlab("Train N") +
scale_color_lancet()
metrics_df_long = metrics_df %>% filter(pca == 'bothhands', npc==6) %>% group_by(patient, smooth) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% pivot_longer(-c(patient, smooth), names_to = "Metric")
metrics_df_long %>% ggplot(aes(x=Metric, y = value, color=Metric)) + geom_jitter() + geom_boxplot(alpha=0) + facet_wrap(~smooth) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (1 session training)") + theme(plot.title = element_text(hjust = 0.5)) +
scale_color_d3()
# Prepare table with smoothing
table1 = metrics_df %>% filter(smooth=="Pre-Smoothing", pca == 'bothhands', npc==6) %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean)
# Prepare table without smoothing
table2 = metrics_df %>% filter(smooth=="Post-Smoothing", pca == 'bothhands', npc==6) %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% as.data.frame()
# Join tables
tables = cbind(table1, table2[, -1]) %>% round(2)
colnames(tables)[2:11] = paste0(colnames(tables)[2:11], rep(c(".T", ".F"), each = 5))
headers = data.frame(col_keys = colnames(tables),
from = c("Session", rep(c("Pre-Smoothing", "Post-Smoothing"), each=5)),
names = c("Session", colnames(cbind(table1[-1], table2[, -1])))
)
# Print table as flextable
tables %>% flextable::flextable() %>%
set_header_df(mapping = headers, key = "col_keys") %>%
merge_h(part="header") %>%
merge_v(part="header") %>%
theme_vanilla() %>%
width(width = 27, unit = "in") %>%
align(align="center", part="all") %>%
vline(part="header")
Session | Pre-Smoothing | Post-Smoothing | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
Accuracy | Precision | F1.score | Sensitivity | Specificity | Accuracy | Precision | F1.score | Sensitivity | Specificity | |
5 | 0.84 | 0.92 | 0.89 | 0.86 | 0.77 | 0.91 | 0.94 | 0.94 | 0.94 | 0.80 |
6 | 0.81 | 0.91 | 0.86 | 0.82 | 0.76 | 0.85 | 0.93 | 0.89 | 0.87 | 0.80 |
8 | 0.81 | 0.91 | 0.86 | 0.83 | 0.75 | 0.87 | 0.93 | 0.91 | 0.90 | 0.78 |
9 | 0.79 | 0.91 | 0.84 | 0.80 | 0.75 | 0.83 | 0.92 | 0.88 | 0.85 | 0.78 |
11 | 0.78 | 0.90 | 0.84 | 0.81 | 0.71 | 0.84 | 0.91 | 0.88 | 0.87 | 0.72 |
12 | 0.72 | 0.89 | 0.77 | 0.71 | 0.74 | 0.75 | 0.90 | 0.79 | 0.75 | 0.75 |
metrics_df_all_n %>%
filter(pca == 'bothhands', npc==6) %>%
group_by(patient, n_train, smooth) %>%
select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>%
summarize_all(mean) %>%
pivot_longer(-c(patient, n_train, smooth), names_to = "Metric") %>%
ggplot(aes(x=n_train, y = value, color=as.factor(n_train))) +
geom_jitter() + facet_grid(smooth~Metric) + geom_boxplot(alpha=0) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (n session training)") +
theme(plot.title = element_text(hjust = 0.5)) + guides(color=guide_legend(title="N trained med sessions")) + xlab("Train N") +
scale_color_lancet()
metrics_df_long = metrics_df %>% filter(pca == 'bothhands', npc==7) %>% group_by(patient, smooth) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% pivot_longer(-c(patient, smooth), names_to = "Metric")
metrics_df_long %>% ggplot(aes(x=Metric, y = value, color=Metric)) + geom_jitter() + geom_boxplot(alpha=0) + facet_wrap(~smooth) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (1 session training)") + theme(plot.title = element_text(hjust = 0.5)) +
scale_color_d3()
# Prepare table with smoothing
table1 = metrics_df %>% filter(smooth=="Pre-Smoothing", pca == 'bothhands', npc==7) %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean)
# Prepare table without smoothing
table2 = metrics_df %>% filter(smooth=="Post-Smoothing", pca == 'bothhands', npc==7) %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% as.data.frame()
# Join tables
tables = cbind(table1, table2[, -1]) %>% round(2)
colnames(tables)[2:11] = paste0(colnames(tables)[2:11], rep(c(".T", ".F"), each = 5))
headers = data.frame(col_keys = colnames(tables),
from = c("Session", rep(c("Pre-Smoothing", "Post-Smoothing"), each=5)),
names = c("Session", colnames(cbind(table1[-1], table2[, -1])))
)
# Print table as flextable
tables %>% flextable::flextable() %>%
set_header_df(mapping = headers, key = "col_keys") %>%
merge_h(part="header") %>%
merge_v(part="header") %>%
theme_vanilla() %>%
width(width = 27, unit = "in") %>%
align(align="center", part="all") %>%
vline(part="header")
Session | Pre-Smoothing | Post-Smoothing | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
Accuracy | Precision | F1.score | Sensitivity | Specificity | Accuracy | Precision | F1.score | Sensitivity | Specificity | |
5 | 0.83 | 0.92 | 0.89 | 0.86 | 0.75 | 0.90 | 0.93 | 0.93 | 0.93 | 0.79 |
6 | 0.80 | 0.91 | 0.84 | 0.81 | 0.76 | 0.84 | 0.91 | 0.86 | 0.85 | 0.79 |
8 | 0.81 | 0.91 | 0.86 | 0.83 | 0.74 | 0.85 | 0.92 | 0.90 | 0.89 | 0.73 |
9 | 0.79 | 0.90 | 0.84 | 0.80 | 0.75 | 0.82 | 0.92 | 0.86 | 0.84 | 0.76 |
11 | 0.78 | 0.90 | 0.84 | 0.80 | 0.72 | 0.83 | 0.92 | 0.87 | 0.86 | 0.74 |
12 | 0.71 | 0.89 | 0.76 | 0.70 | 0.74 | 0.74 | 0.90 | 0.77 | 0.73 | 0.79 |
metrics_df_all_n %>%
filter(pca == 'bothhands', npc==7) %>%
group_by(patient, n_train, smooth) %>%
select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>%
summarize_all(mean) %>%
pivot_longer(-c(patient, n_train, smooth), names_to = "Metric") %>%
ggplot(aes(x=n_train, y = value, color=as.factor(n_train))) +
geom_jitter() + facet_grid(smooth~Metric) + geom_boxplot(alpha=0) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (n session training)") +
theme(plot.title = element_text(hjust = 0.5)) + guides(color=guide_legend(title="N trained med sessions")) + xlab("Train N") +
scale_color_lancet()
metrics_df_long = metrics_df %>% filter(pca == 'bothhands', npc==8) %>% group_by(patient, smooth) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% pivot_longer(-c(patient, smooth), names_to = "Metric")
metrics_df_long %>% ggplot(aes(x=Metric, y = value, color=Metric)) + geom_jitter() + geom_boxplot(alpha=0) + facet_wrap(~smooth) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (1 session training)") + theme(plot.title = element_text(hjust = 0.5)) +
scale_color_d3()
# Prepare table with smoothing
table1 = metrics_df %>% filter(smooth=="Pre-Smoothing", pca == 'bothhands', npc==8) %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean)
# Prepare table without smoothing
table2 = metrics_df %>% filter(smooth=="Post-Smoothing", pca == 'bothhands', npc==8) %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% as.data.frame()
# Join tables
tables = cbind(table1, table2[, -1]) %>% round(2)
colnames(tables)[2:11] = paste0(colnames(tables)[2:11], rep(c(".T", ".F"), each = 5))
headers = data.frame(col_keys = colnames(tables),
from = c("Session", rep(c("Pre-Smoothing", "Post-Smoothing"), each=5)),
names = c("Session", colnames(cbind(table1[-1], table2[, -1])))
)
# Print table as flextable
tables %>% flextable::flextable() %>%
set_header_df(mapping = headers, key = "col_keys") %>%
merge_h(part="header") %>%
merge_v(part="header") %>%
theme_vanilla() %>%
width(width = 27, unit = "in") %>%
align(align="center", part="all") %>%
vline(part="header")
Session | Pre-Smoothing | Post-Smoothing | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
Accuracy | Precision | F1.score | Sensitivity | Specificity | Accuracy | Precision | F1.score | Sensitivity | Specificity | |
5 | 0.84 | 0.92 | 0.89 | 0.86 | 0.75 | 0.89 | 0.93 | 0.93 | 0.93 | 0.77 |
6 | 0.79 | 0.90 | 0.84 | 0.81 | 0.75 | 0.84 | 0.91 | 0.86 | 0.86 | 0.81 |
8 | 0.81 | 0.91 | 0.86 | 0.83 | 0.74 | 0.85 | 0.92 | 0.90 | 0.89 | 0.75 |
9 | 0.78 | 0.91 | 0.84 | 0.79 | 0.75 | 0.83 | 0.93 | 0.87 | 0.84 | 0.81 |
11 | 0.78 | 0.91 | 0.84 | 0.80 | 0.73 | 0.84 | 0.92 | 0.87 | 0.86 | 0.77 |
12 | 0.71 | 0.90 | 0.77 | 0.70 | 0.76 | 0.75 | 0.91 | 0.78 | 0.73 | 0.80 |
metrics_df_all_n %>%
filter(pca == 'bothhands', npc==8) %>%
group_by(patient, n_train, smooth) %>%
select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>%
summarize_all(mean) %>%
pivot_longer(-c(patient, n_train, smooth), names_to = "Metric") %>%
ggplot(aes(x=n_train, y = value, color=as.factor(n_train))) +
geom_jitter() + facet_grid(smooth~Metric) + geom_boxplot(alpha=0) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (n session training)") +
theme(plot.title = element_text(hjust = 0.5)) + guides(color=guide_legend(title="N trained med sessions")) + xlab("Train N") +
scale_color_lancet()
metrics_df_long = metrics_df %>% filter(pca == 'bothhands', npc==9) %>% group_by(patient, smooth) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% pivot_longer(-c(patient, smooth), names_to = "Metric")
metrics_df_long %>% ggplot(aes(x=Metric, y = value, color=Metric)) + geom_jitter() + geom_boxplot(alpha=0) + facet_wrap(~smooth) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (1 session training)") + theme(plot.title = element_text(hjust = 0.5)) +
scale_color_d3()
# Prepare table with smoothing
table1 = metrics_df %>% filter(smooth=="Pre-Smoothing", pca == 'bothhands', npc==9) %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean)
# Prepare table without smoothing
table2 = metrics_df %>% filter(smooth=="Post-Smoothing", pca == 'bothhands', npc==9) %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% as.data.frame()
# Join tables
tables = cbind(table1, table2[, -1]) %>% round(2)
colnames(tables)[2:11] = paste0(colnames(tables)[2:11], rep(c(".T", ".F"), each = 5))
headers = data.frame(col_keys = colnames(tables),
from = c("Session", rep(c("Pre-Smoothing", "Post-Smoothing"), each=5)),
names = c("Session", colnames(cbind(table1[-1], table2[, -1])))
)
# Print table as flextable
tables %>% flextable::flextable() %>%
set_header_df(mapping = headers, key = "col_keys") %>%
merge_h(part="header") %>%
merge_v(part="header") %>%
theme_vanilla() %>%
width(width = 27, unit = "in") %>%
align(align="center", part="all") %>%
vline(part="header")
Session | Pre-Smoothing | Post-Smoothing | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
Accuracy | Precision | F1.score | Sensitivity | Specificity | Accuracy | Precision | F1.score | Sensitivity | Specificity | |
5 | 0.84 | 0.92 | 0.89 | 0.86 | 0.74 | 0.90 | 0.93 | 0.93 | 0.94 | 0.77 |
6 | 0.79 | 0.90 | 0.84 | 0.80 | 0.76 | 0.85 | 0.92 | 0.88 | 0.86 | 0.82 |
8 | 0.81 | 0.91 | 0.86 | 0.83 | 0.74 | 0.85 | 0.92 | 0.90 | 0.89 | 0.73 |
9 | 0.78 | 0.90 | 0.83 | 0.79 | 0.75 | 0.83 | 0.93 | 0.87 | 0.84 | 0.81 |
11 | 0.78 | 0.91 | 0.83 | 0.79 | 0.75 | 0.83 | 0.92 | 0.87 | 0.85 | 0.75 |
12 | 0.72 | 0.90 | 0.77 | 0.70 | 0.77 | 0.75 | 0.90 | 0.79 | 0.74 | 0.80 |
metrics_df_all_n %>%
filter(pca == 'bothhands', npc==9) %>%
group_by(patient, n_train, smooth) %>%
select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>%
summarize_all(mean) %>%
pivot_longer(-c(patient, n_train, smooth), names_to = "Metric") %>%
ggplot(aes(x=n_train, y = value, color=as.factor(n_train))) +
geom_jitter() + facet_grid(smooth~Metric) + geom_boxplot(alpha=0) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (n session training)") +
theme(plot.title = element_text(hjust = 0.5)) + guides(color=guide_legend(title="N trained med sessions")) + xlab("Train N") +
scale_color_lancet()
metrics_df_long = metrics_df %>% filter(pca == 'bothhands', npc==10) %>% group_by(patient, smooth) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% pivot_longer(-c(patient, smooth), names_to = "Metric")
metrics_df_long %>% ggplot(aes(x=Metric, y = value, color=Metric)) + geom_jitter() + geom_boxplot(alpha=0) + facet_wrap(~smooth) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (1 session training)") + theme(plot.title = element_text(hjust = 0.5)) +
scale_color_d3()
# Prepare table with smoothing
table1 = metrics_df %>% filter(smooth=="Pre-Smoothing", pca == 'bothhands', npc==10) %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean)
# Prepare table without smoothing
table2 = metrics_df %>% filter(smooth=="Post-Smoothing", pca == 'bothhands', npc==10) %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% as.data.frame()
# Join tables
tables = cbind(table1, table2[, -1]) %>% round(2)
colnames(tables)[2:11] = paste0(colnames(tables)[2:11], rep(c(".T", ".F"), each = 5))
headers = data.frame(col_keys = colnames(tables),
from = c("Session", rep(c("Pre-Smoothing", "Post-Smoothing"), each=5)),
names = c("Session", colnames(cbind(table1[-1], table2[, -1])))
)
# Print table as flextable
tables %>% flextable::flextable() %>%
set_header_df(mapping = headers, key = "col_keys") %>%
merge_h(part="header") %>%
merge_v(part="header") %>%
theme_vanilla() %>%
width(width = 27, unit = "in") %>%
align(align="center", part="all") %>%
vline(part="header")
Session | Pre-Smoothing | Post-Smoothing | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
Accuracy | Precision | F1.score | Sensitivity | Specificity | Accuracy | Precision | F1.score | Sensitivity | Specificity | |
5 | 0.83 | 0.91 | 0.88 | 0.85 | 0.74 | 0.89 | 0.92 | 0.93 | 0.93 | 0.75 |
6 | 0.79 | 0.90 | 0.84 | 0.80 | 0.76 | 0.84 | 0.92 | 0.86 | 0.84 | 0.83 |
8 | 0.80 | 0.91 | 0.86 | 0.83 | 0.73 | 0.84 | 0.92 | 0.89 | 0.87 | 0.74 |
9 | 0.78 | 0.90 | 0.83 | 0.79 | 0.75 | 0.82 | 0.92 | 0.86 | 0.83 | 0.77 |
11 | 0.78 | 0.91 | 0.83 | 0.78 | 0.76 | 0.83 | 0.93 | 0.87 | 0.84 | 0.79 |
12 | 0.71 | 0.91 | 0.76 | 0.69 | 0.78 | 0.73 | 0.91 | 0.77 | 0.72 | 0.80 |
metrics_df_all_n %>%
filter(pca == 'bothhands', npc==10) %>%
group_by(patient, n_train, smooth) %>%
select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>%
summarize_all(mean) %>%
pivot_longer(-c(patient, n_train, smooth), names_to = "Metric") %>%
ggplot(aes(x=n_train, y = value, color=as.factor(n_train))) +
geom_jitter() + facet_grid(smooth~Metric) + geom_boxplot(alpha=0) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (n session training)") +
theme(plot.title = element_text(hjust = 0.5)) + guides(color=guide_legend(title="N trained med sessions")) + xlab("Train N") +
scale_color_lancet()
metrics_df_long = metrics_df %>% filter(pca == 'dominanthand') %>% group_by(patient, smooth) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% pivot_longer(-c(patient, smooth), names_to = "Metric")
metrics_df_long %>% ggplot(aes(x=Metric, y = value, color=Metric)) + geom_jitter() + geom_boxplot(alpha=0) + facet_wrap(~smooth) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (1 session training)") + theme(plot.title = element_text(hjust = 0.5)) +
scale_color_d3()
# Prepare table with smoothing
table1 = metrics_df %>% filter(smooth=="Pre-Smoothing", pca == 'dominanthand') %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean)
# Prepare table without smoothing
table2 = metrics_df %>% filter(smooth=="Post-Smoothing", pca == 'dominanthand') %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% as.data.frame()
# Join tables
tables = cbind(table1, table2[, -1]) %>% round(2)
colnames(tables)[2:11] = paste0(colnames(tables)[2:11], rep(c(".T", ".F"), each = 5))
headers = data.frame(col_keys = colnames(tables),
from = c("Session", rep(c("Pre-Smoothing", "Post-Smoothing"), each=5)),
names = c("Session", colnames(cbind(table1[-1], table2[, -1])))
)
# Print table as flextable
tables %>% flextable::flextable() %>%
set_header_df(mapping = headers, key = "col_keys") %>%
merge_h(part="header") %>%
merge_v(part="header") %>%
theme_vanilla() %>%
width(width = 27, unit = "in") %>%
align(align="center", part="all") %>%
vline(part="header")
Session | Pre-Smoothing | Post-Smoothing | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
Accuracy | Precision | F1.score | Sensitivity | Specificity | Accuracy | Precision | F1.score | Sensitivity | Specificity | |
5 | 0.82 | 0.91 | 0.87 | 0.85 | 0.73 | 0.87 | 0.92 | 0.91 | 0.91 | 0.74 |
6 | 0.78 | 0.90 | 0.84 | 0.80 | 0.72 | 0.84 | 0.91 | 0.89 | 0.87 | 0.74 |
8 | 0.81 | 0.90 | 0.86 | 0.83 | 0.72 | 0.87 | 0.92 | 0.91 | 0.92 | 0.73 |
9 | 0.79 | 0.90 | 0.85 | 0.81 | 0.74 | 0.84 | 0.92 | 0.88 | 0.86 | 0.76 |
11 | 0.76 | 0.88 | 0.82 | 0.77 | 0.70 | 0.82 | 0.90 | 0.86 | 0.85 | 0.72 |
12 | 0.71 | 0.89 | 0.76 | 0.69 | 0.75 | 0.74 | 0.91 | 0.79 | 0.74 | 0.75 |
metrics_df_all_n %>%
filter(pca == 'dominanthand') %>%
group_by(patient, n_train, smooth) %>%
select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>%
summarize_all(mean) %>%
pivot_longer(-c(patient, n_train, smooth), names_to = "Metric") %>%
ggplot(aes(x=n_train, y = value, color=as.factor(n_train))) +
geom_jitter() + facet_grid(smooth~Metric) + geom_boxplot(alpha=0) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (n session training)") +
theme(plot.title = element_text(hjust = 0.5)) + guides(color=guide_legend(title="N trained med sessions")) + xlab("Train N") +
scale_color_lancet()
metrics_df_long = metrics_df %>% filter(pca == 'nondominanthand') %>% group_by(patient, smooth) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% pivot_longer(-c(patient, smooth), names_to = "Metric")
metrics_df_long %>% ggplot(aes(x=Metric, y = value, color=Metric)) + geom_jitter() + geom_boxplot(alpha=0) + facet_wrap(~smooth) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (1 session training)") + theme(plot.title = element_text(hjust = 0.5)) +
scale_color_d3()
# Prepare table with smoothing
table1 = metrics_df %>% filter(smooth=="Pre-Smoothing", pca == 'nondominanthand') %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean)
# Prepare table without smoothing
table2 = metrics_df %>% filter(smooth=="Post-Smoothing", pca == 'nondominanthand') %>% group_by(session) %>% select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>% summarize_all(mean) %>% as.data.frame()
# Join tables
tables = cbind(table1, table2[, -1]) %>% round(2)
colnames(tables)[2:11] = paste0(colnames(tables)[2:11], rep(c(".T", ".F"), each = 5))
headers = data.frame(col_keys = colnames(tables),
from = c("Session", rep(c("Pre-Smoothing", "Post-Smoothing"), each=5)),
names = c("Session", colnames(cbind(table1[-1], table2[, -1])))
)
# Print table as flextable
tables %>% flextable::flextable() %>%
set_header_df(mapping = headers, key = "col_keys") %>%
merge_h(part="header") %>%
merge_v(part="header") %>%
theme_vanilla() %>%
width(width = 27, unit = "in") %>%
align(align="center", part="all") %>%
vline(part="header")
Session | Pre-Smoothing | Post-Smoothing | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
Accuracy | Precision | F1.score | Sensitivity | Specificity | Accuracy | Precision | F1.score | Sensitivity | Specificity | |
5 | 0.74 | 0.90 | 0.81 | 0.74 | 0.72 | 0.79 | 0.91 | 0.84 | 0.80 | 0.73 |
6 | 0.73 | 0.89 | 0.79 | 0.73 | 0.71 | 0.77 | 0.90 | 0.82 | 0.78 | 0.76 |
8 | 0.73 | 0.89 | 0.79 | 0.73 | 0.70 | 0.77 | 0.89 | 0.81 | 0.78 | 0.69 |
9 | 0.73 | 0.88 | 0.79 | 0.73 | 0.69 | 0.76 | 0.89 | 0.82 | 0.78 | 0.68 |
11 | 0.69 | 0.87 | 0.75 | 0.69 | 0.67 | 0.73 | 0.89 | 0.78 | 0.73 | 0.70 |
12 | 0.68 | 0.88 | 0.75 | 0.68 | 0.69 | 0.72 | 0.88 | 0.77 | 0.72 | 0.68 |
metrics_df_all_n %>%
filter(pca == 'nondominanthand') %>%
group_by(patient, n_train, smooth) %>%
select(Accuracy, Precision, F1.score, Sensitivity, Specificity) %>%
summarize_all(mean) %>%
pivot_longer(-c(patient, n_train, smooth), names_to = "Metric") %>%
ggplot(aes(x=n_train, y = value, color=as.factor(n_train))) +
geom_jitter() + facet_grid(smooth~Metric) + geom_boxplot(alpha=0) +
theme_bw() + ggtitle("Summary metrics for Movelet prediction (n session training)") +
theme(plot.title = element_text(hjust = 0.5)) + guides(color=guide_legend(title="N trained med sessions")) + xlab("Train N") +
scale_color_lancet()